package com.goldenautumn.prefabricate.activity.home

import android.content.Context
import android.graphics.Color
import android.view.ViewGroup
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.DataBindingHolder
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.business.entity.HomeItemDataVo
import com.goldenautumn.prefabricate.databinding.ItemHomeMenuBinding
import com.goldenautumn.prefabricate.utils.loadImgUrl

class HomeMenuAdapter   : BaseQuickAdapter<HomeItemDataVo, DataBindingHolder<ItemHomeMenuBinding>>() {

    override fun onBindViewHolder(holder: DataBindingHolder<ItemHomeMenuBinding>, position: Int, item: HomeItemDataVo?) {
        if(item == null) return
        var mBinding  = holder.binding

        var itemWidth = (ScreenUtils.getScreenWidth() - SizeUtils.dp2px(80f)) / 4
        var lp = mBinding.icon.layoutParams
        lp.width = itemWidth
        lp.height = itemWidth
//        mBinding.icon.loadImgUrl(item.imgUrl)
        mBinding.title.text = "${item.text}"
        mBinding.title.setTextColor(Color.parseColor(item.color))
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): DataBindingHolder<ItemHomeMenuBinding> {
        return DataBindingHolder(R.layout.item_home_menu,parent)
    }

    override fun getItemCount(items: List<HomeItemDataVo>): Int {
        return if(items.size > 10) 10 else super.getItemCount(items)
    }

}